<?php
namespace Mana\Controller;

use Think\Controller;

class IndexController extends Controller
{
    public function index()
    {
        $this->display();
    }
    
    public function login()
    {
        $manager=M("manager");
        
        $post=I("post.");
        $where=array(
            "mag_name"=>$post['name'],
            "mag_pass"=>$this->passEncode($post['pass']),
            'mag_type'=>5,
            'mag_active'=>1
        );
        $info=$manager->where($where)->find();
        if ($info['mag_name']!=null) {
            session("dataHomeRabc", $info['mag_id']);
            $this->redirect("Dash/index");
        } else {
            $this->error("用户名或密码错误");
        }
    }
    
    public function out()
    {
        session("dataHomeRabc", null);
        if (session("dataHomeRabc")==null) {
            $this->redirect("Index/index");
        } else {
            session_destroy();
            $this->redirect("Index/index");
        }
    }
    
    private function passEncode($str)
    {
        $pa = substr(md5(trim($str)), 10, 15);
        preg_match('/[0-9]+/', $str, $result);
        $ss = substr(md5(trim($result[0])), 22, 5);
        return $pa . $ss;
    }
}
